package com.zmn.oms.common.utils;

import com.zmn.common.utils.math.MathUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.pay.common.constant.PayConsts;

import java.util.Objects;

/**
 * @author sunlife
 * @date:2022/4/18 下午5:50
 * description: 工单金额工具类
 */
public class WorkAmountUtil {

    /**
     * 获取工单已经支付的金额
     * @param orderWork
     * @return
     */
    public static Integer getWorkFactAmount(OrderWork orderWork) {
        // 处理已付金额
        Integer factAmount = 0;
        if (Objects.equals(orderWork.getChannelPrepayStatus(), PayConsts.PAY_STATUS_DONE) && !NumberUtil
                .isNullOrZero(orderWork.getChannelPrepayAmount())) {
            factAmount = factAmount + orderWork.getChannelPrepayAmount().intValue();
        }
        if (Objects.equals(orderWork.getPrepayStatus(), PayConsts.PAY_STATUS_DONE) && !NumberUtil
                .isNullOrZero(orderWork.getPrepayAmount())) {
            factAmount = factAmount + orderWork.getPrepayAmount().intValue();
        }
        if (Objects.equals(orderWork.getDepositStatus(), PayConsts.PAY_STATUS_DONE) && !NumberUtil
                .isNullOrZero(orderWork.getDepositAmount())) {
            factAmount = factAmount + orderWork.getDepositAmount().intValue();
        }
        if (Objects.equals(orderWork.getMasterPayStatus(), PayConsts.PAY_STATUS_DONE) && !NumberUtil
                .isNullOrZero(orderWork.getMasterAmount())) {
            factAmount = factAmount + orderWork.getMasterAmount().intValue();
        }
        if (Objects.equals(orderWork.getType(), OrderConsts.ORDER_TYPE_REFUND) && !NumberUtil.isNullOrZero(orderWork.getRefundAmount())) {
            factAmount = MathUtil.sub(factAmount, orderWork.getRefundAmount());
        }
        return factAmount;
    }

}
